#!/bin/bash

>mysql.txt
read -p "please input long distance ip address:" ip
local=`ifconfig eth0 |egrep "inet" |awk -F: '{print $2}'|awk '{print $1}' |head -n 1`
ti=`date`
flage=0
while flage=0;
do
in1=`nc -z ${local} 3306`
if [[ $? == 0 ]];then
	echo "${ti}$in1" >>mysql.txt
	echo "${ti}$in1"
	flage=1
else
	echo "${ti}${local} mysql server is down"
	echo "${ti}${local} mysql server is down" >>mysql.txt
	flage=0
fi

in2=`nc -z ${ip} 3306` 
if [[ $? == 0 ]];then
        echo "${ti}$in2" >mysql.txt
        echo "${ti}$in2"
	flage=0
else
        echo "${ti}${ip} mysql server is down"
        echo "${ti}${ip} mysql server is down" >>mysql.txt
	flage=1
fi

sleep 1
done
